<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <meta name="description" content="">
    <meta name="author" content="">
    <title>$app.topic 登陆</title>

    <link href="/vendor/fontawesome-free/css/all.min.css" rel="stylesheet" type="text/css">
    <!-- Custom styles for this template-->
    <link href="/css/sb-admin.min.css" rel="stylesheet">
    <link href="/css/extends.css" rel="stylesheet">

</head>
<body class="bg-dark">

<div class="container">
    <div class="card card-login mx-auto mt-5">
        <div class="card-header">登陆</div>
        <div class="card-body">
            <form id="login-form" method="post" action="/hashlogin">
                <input type="hidden" id="url" value="$!url">
                <div class="form-group">
                    <div class="form-label-group">
                        <input type="tel" id="tel" class="form-control" placeholder="手机号码" required="required" autofocus="autofocus">
                        <label for="tel">请输入手机号</label>
                    </div>
                </div>
                <div class="form-group">
                    <div class="form-label-group">
                        <input type="password" id="password" class="form-control" placeholder="登陆密码" required="required">
                        <label for="password">请输入密码</label>
                    </div>
                </div>
                <div class="form-group">
                    <div class="checkbox">
                        <label>
                            <input type="checkbox" value="remember-me" id="remember">
                            记住密码
                        </label>
                    </div>
                </div>
                <button type="submit" class="btn btn-primary btn-block"
                 id="login_button" onclick="hashlogin();">登陆</button>
            </form>
            <div id="errormsg">
            </div>
        </div>
    </div>
</div>

<!-- Bootstrap core JavaScript-->
<script src="/vendor/jquery/jquery.min.js"></script>
<script src="/vendor/bootstrap/js/bootstrap.bundle.min.js"></script>
<!-- Core plugin JavaScript-->
<script src="/vendor/jquery-easing/jquery.easing.min.js"></script>

<script>

    $("#login-form").on("submit",hashlogin)

    function hashlogin(){
        var tel = $("#tel").val();
        if(!tel){
            render_error("请输入登陆手机号码");
            return false;
        }
        var password = $("#password").val();
        if(!password){
            render_error("请输入有效登陆密码");
            return false;
        }
        var url = $("#url").val();
        var error = $("#errormsg") ;
        error.text("");
        error.hide();
        $.ajax({
            url:"/hashlogin",
            data:{tel: tel, password: password, url:url},
            type:"POST"
        }).done(function(res){
            if(res.state==="000"){
                error.removeClass("alert-danger").addClass("alert-success") ;
                error.text("登陆成功")
                location.href = !res.data ? "/index" : res.data;
                error.hide();
            }else{
                render_error(res.msg);
            }
        })
            .fail(function (res) {
                var status = res.status?res.status:"-1"
                render_error("服务器错误 "+ status)
            })

        return false ;
    }

    function render_error(msg) {
        var error = $("#errormsg") ;
        error.removeClass("alert-success").addClass("alert-danger") ;
        error.text(msg);
        error.show();
    }

</script>

</body>
</html>